-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alts: Make GoogleDefaultChannelCredentials take a CallCredentials #8548
Conversation
I'm delaying reviewing this until the design is worked out for all the languages. |
I added a |
"Compute Engine Credentials can only be used on Google Cloud Platform")); | ||
} | ||
if (callCredentials == null) { | ||
callCredentials = MoreCallCredentials.from(ComputeEngineCredentials.create()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mutate the builder. Instead, use a local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
callCredentials = | ||
new FailingCallCredentials( | ||
Status.INTERNAL.withDescription( | ||
"Compute Engine Credentials can only be used on Google Cloud Platform")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... This is a bit interesting, as if the user is providing call credentials we could actually work on non-GCE.
I wonder if we are modifying the wrong API, and should be modifying GoogleDefaultChannelCredentials instead. CC @menghanl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gax-java and google-api-go-client will check the GCP environment before attempting DirectPath, see https://github.com/googleapis/gax-java/blob/main/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java#L336 and https://github.com/googleapis/google-api-go-client/blob/master/transport/grpc/dial.go#L141.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, or we should just add a general purpose API that accepts callCreds.
And both GoogleDefaultCreds
and ComputeEngineCreds
should be built on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this? grpc/grpc-go#4830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gax-java and google-api-go-client will check the GCP environment before attempting DirectPath
So what? That has little to do with the implementation and times it could be used. The point is that this API has no dependency on GCE when you provide the credentials.
And both GoogleDefaultCreds and ComputeEngineCreds should be built on that.
I think that is essentially "GoogleDefaultCreds with passed call creds" like I was suggesting. And it seems that is the approach you took with grpc/grpc-go#4830, so I think we are on the same page.
We should modify GoogleDefaultChannelCredentials in Java instead of ComputeEngineChannelCredentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I have two concerns here:
-
Your opinion is from the perspective of API design, which makes sense to me. However, if you look from the perspective of DirectPath, since DirectPath can only be used on GCE, removing the checking on GCE in credentials (i.e., using GoogleDefaultCreds instead of ComputeEngineCreds) means that we relies on client libraries (i.e., the two links above) to check the GCE environment. I doubt if this is a good design, and I feel the secure solution here is to rename ComputeEngineCreds in this PR to DirectPathCreds (if ComputeEngineCreds is only used by DirectPath, and if not we can just create a new API), so that it will makes sense that the new API can take call credentials while also have dependency on GCE. WDYT? Also @menghanl
-
I remember originally we first developed GoogleDefaultCreds, but as client libraries owners wanted to know for sure what mechanism would be used to retrieve the OAuth token, so we then developed ComputeEngineCreds. @apolcyn Alex may have more context here. If after discussing Q1 we still want to use GoogleDefaultCreds for DirectPath, we should reach to client libraries owners as same concerns may still exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since DirectPath can only be used on GCE
For 1, as you mention, the only reason ComputeEngineChannelCredentials exists is because the client libraries wanted to convert from their version of ComputeEngine creds and guarantee that GoogleDefaultChannelCredentials didn't use some other sort of cred. GoogleDefaultChannelCredentials was designed to run anywhere.
For 2, if the client libraries are explicitly passing the call credentials they expect to be used, then there's no mis-alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with 2.
For 1 I want to double check, you think it is OK that DirectPath will use GoogleDefaultChannelCredentials, and since GoogleDefaultChannelCredentials does not do the on GCE check, we rely on client libraries to do the on GCE check, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how I can say this any differently. GoogleDefaultChannelCredentials is fine to use outside of GCE. If client libraries only want to use it for GCE, that is fine and up to them. Both GoogleDefaultChannelCredentials and ComputeEngineChannelCredentials do not require ALTS to work; they will fall back to TLS if anything goes wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for clarifying. I have updated the PR. PTAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fair. Once the two comments are resolved it'd be good to merge.
alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java
Outdated
Show resolved
Hide resolved
alts/src/main/java/io/grpc/alts/GoogleDefaultChannelCredentials.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me. Since this is direct-to-stable since it is being used by a library, I'm going to hold off on merging until it is discussed in the API stabilization meeting on the 14th.
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare private Builder() {}
to favor static newBuilder()
over new Builder()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return newBuilder().build(); | ||
} | ||
|
||
public static Builder newBuilder() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add javadoc and @since 1.42.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
sslContext = GrpcSslContexts.forClient().build(); | ||
} catch (SSLException e) { | ||
throw new RuntimeException(e); | ||
/** Builder for {@link GoogleDefaultChannelCredentials} instances. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add @since 1.42.0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
public static final class Builder { | ||
private CallCredentials callCredentials; | ||
|
||
/** Construct GoogleDefaultChannelCredentials with a given call credential. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/Construct/Constructs/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return this; | ||
} | ||
|
||
/** Build a GoogleDefaultChannelCredentials instance. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/Build/Builds/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
API review:
|
DirectPath is going to support non-default service account. This PR allows users to pass
CallCredentials
toGoogleDefaultChannelCredentials
. See design in https://docs.google.com/document/d/1JmyqJBFlVKjPvceJ0-QCDrqNHXxAHbelzrohtZp9YmE/edit?resourcekey=0-FqL0OJdgTsgxX5jbMsPuVg#heading=h.8wyuqdk8ouwm.